from gameset.phoenicia.base import *


class Wood(RawMaterial):
    singular =_ ('Wood')
    plural   =_ ('Wood')


class Firewood(Wood):
    singular =_ ('Firewood')
    plural   =_ ('Firewood')
    price    =_ (100)


class Cedar(Wood):
    singular =_ ('Cedar')
    plural   =_ ('Cedar')
    price    =_ (500)


class Lumberjack(Seeker):
    color    =_ (Green.with_value(0.2))
    speed    =_ (5)
    radius   =_ (5)
    capacity =_ (50)
    
    def on_idle(self):
        if self.tile.terrain.type is not Forest:
            self.move_around()
    
    def move_around(self):
        position = self.home.position.random_nearby(self.radius)
        tile     = self.city.map.at(position)
        
        if tile.is_passable and tile.terrain.type is Forest:
            self.move_to(position)
    
    def day(self, day, month, year):
        if self.tile.terrain.type is Forest:
            self.create(Firewood(5))
            self.create(Cedar(1))
        
        if self.storage.is_full:
            self.move_home()
    
    def on_arrival_home(self):
        self.unload_into(self.home)
        self.destroy()


class Sawmill(StaffedBuilding):
    name       =_ ('Sawmill')
    color      =_ (Green.with_value(0.2))
    profession =_ (Lumberjack)
    cost       =_ (150)
    staff      =_ (15)
    agents     =_ (4)
    size       =_ (3)
    stores     =_ (Firewood(1000), Cedar(250))
    
    @property
    def supply(self):
        return (Cedar, Firewood)
    
    @property
    def spawn_point(self):
        return self.access_point
